# coding:utf-8
# 曾山
# 时间 2022/4/30 11:58

from flask import Flask

from setting import map_config






def create_app(config_type):
    app = Flask(__name__)
    #加载项目的配置
    app.config.from_object(map_config.get(config_type))
    #初始化限流器
    from comment.utils.limiter import limiter as lim
    lim.init_app(app)

    #加载日志处理的工具
    from comment.utils.logging import create_logger
    create_logger(app)
    #初始化sqlalchemy
    from comment.models import db
    db.init_app(app)
    #初始化redis数据库的连接
    from comment.utils.shopping_redis import redis_cenlit
    redis_cenlit.init_app(app)
    # 添加请求钩子,每次请求之前
    from comment.utils.requests_wares import jwt_request_authorization
    app.before_request(jwt_request_authorization)
    #加载模块的蓝图
    from Shopping.resources.user import user_bp
    app.register_blueprint(user_bp)
    from Shopping.resources.index import index_bp
    app.register_blueprint(index_bp)
    from Shopping.resources.goods import goods_bp
    app.register_blueprint(goods_bp)
    return app